import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import store from './store/index'
import './api/mock.js'
import api from './api/api'
// import ElementPlus from "element-plus";
// import "element-plus/dist/index.css";

const app = createApp(App)
// 向所有组件注入 api 对象
app.config.globalProperties.$api = api

// store.commit('addMenu', router)
// function checkRouter(path) {
//   let hasCheck = router.getRoutes().filter((route) => route.path == path).length
//   console.log(router.getRoutes())
//   if (hasCheck) {
//     return true
//   } else {
//     return false
//   }
// }

// router.beforeEach((to, from, next) => {
//   store.commit('getToken')
//   const token = store.state.token
//   if (!token && to.name !== 'login') {
//     next({ name: 'login' })
//   } else if (!checkRouter(to.path)) {
//     next({ name: 'home' })
//   }
// })
//读到这一行会进入到router
app.use(router).use(store)
// app.use(ElementPlus);
app.mount('#app')
//导入icon,之后就可以通过component标签使用icon了
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
